/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vista;

import com.alee.laf.table.WebTable;
import java.awt.Component;
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author Edder
 */
public final class Utilidades {
    /**
     * Da formato a moneda
     * @param monto
     * @return 
     */
    public static String setUpMoneda(float monto){
        NumberFormat moneda = NumberFormat.getCurrencyInstance(new Locale("es", "PE"));
        return moneda.format(monto);
    }
    
    public static void alinearColumna_derecha(WebTable tabla, String col){
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT);
        tabla.getColumn(col).setCellRenderer( rightRenderer );
    }
    
    public static void resizeColumnWidth(WebTable table) {
        TableColumnModel columnModel = table.getColumnModel();
        for (int column = 0; column < table.getColumnCount(); column++) {
            int width = 10; // Min width            
            for (int row = 0; row < table.getRowCount(); row++) {
                TableCellRenderer renderer = table.getCellRenderer(row, column);
                Component comp = table.prepareRenderer(renderer, row, column);
                width = Math.max(comp.getPreferredSize().width, width);
            }
            columnModel.getColumn(column).setPreferredWidth(width);
        }
}
}
